#include "GeoNode.h"
namespace sl
{
	
	GeoNode::GeoNode(void)
	{
	}

	GeoNode::~GeoNode(void)
	{
		DrawableList::iterator drawableit;
		for ( drawableit = m_vDrawableList.begin(); drawableit != m_vDrawableList.end(); ++drawableit )
		{
			(*drawableit)->RemoveParent(this);
		}
		m_vDrawableList.clear();
	}

	bool GeoNode::AddDrawable( sl::Drawable * pDrawable )
	{
		if ( pDrawable ==  NULL )
			return false;

		pDrawable->AddParent( this );
		m_vDrawableList.push_back( pDrawable );

		return true;
	}

	bool GeoNode::RemoveDrawable( sl::Drawable * pDrawable )
	{
		return RemoveDrawable( getDrawableIndex( pDrawable ) ); 
	}

	bool GeoNode::RemoveDrawable( u32 nIndex )
	{
		if ( nIndex < m_vDrawableList.size() && nIndex >= 0 )
		{
			Drawable * drawable = m_vDrawableList[nIndex].get();
			drawable->RemoveParent(this);
			m_vDrawableList.erase( m_vDrawableList.begin() + nIndex );
			return true;
		}
		else
			return false;
	}

	
	void GeoNode::Accept( sl::NodeVisitor * pNodeVisitor )
	{

	}

	void GeoNode::Ascend( sl::NodeVisitor * pNodeVisitor )
	{

	}

	void GeoNode::Traverse( sl::NodeVisitor * pNodeVisitor )
	{

	}

	u32 GeoNode::getDrawableIndex( sl::Drawable * pDrawable )
	{
		for ( u32 nIndexNum = 0; nIndexNum < m_vDrawableList.size(); ++nIndexNum )
		{
			if ( m_vDrawableList[ nIndexNum ].get() == pDrawable )
					return nIndexNum;
		}
		return m_vDrawableList.size();
	}

}
